(function() {
    Path.on('/admin/__basename__.html', function(_current_location) {
        App.set('admin_title', '图文消息');

        var qs = _current_location.query;
        var offset = qs.get('offset') || 0;
        App.set('$Cache.admin.sourcearticle.offset', offset);
        var count = qs.get('count') || 12;
        App.set('$Cache.admin.sourcearticle.count', count);

        // 获取素材统计
        coAjax.get(apis.wx.business.sourceCount, function(result) {
            console.log(result);
            var pages = [];
            pages.length = Math.ceil(result.news_count / count);
            App.set('$Cache.admin.sourcearticle.pages', pages);
        }, function(errCode, errMsg, err) {
            alert('warn', errMsg);
        });
        // 获取素材列表
        coAjax.get(apis.wx.business.sourceList + 'news', {
            offset: offset || 0,
            count: count || 12
        }, function(result) {
            console.log(result);
            App.set('$Cache.admin.sourcearticle.news', result);
            alert('拉取数据成功');
        }, function(errCode, errMsg, err) {
            alert('warn', errMsg);
        });

        App.set('$Event.admin.sourcearticle.delete', function(e, vm) {
            console.log(vm.get('media_id'))
            alert('warn', '此功能暂未开放');
        })
    });
}());
